package studio7Omega.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import studio7Omega.dao.SalaDAO;
import studio7Omega.excepcion.DAOExcepcion;
import studio7Omega.modelo.Instrumento;
import studio7Omega.modelo.Sala;

/**
 * Servlet implementation class ArmadoSalaGuardarServlet
 */
@WebServlet("/ArmadoSalaGuardarServlet")
public class ArmadoSalaGuardarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ArmadoSalaGuardarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//Obtewniendo parametros
		try {
			int codsala = Integer.parseInt(request.getParameter("cbSala"));
		int codinst = Integer.parseInt(request.getParameter("cbInstrumento"));
		
		System.out.println("codigo sala = "+codsala);
		Sala sala = new SalaDAO().buscarSalaPorId(codsala);
		Instrumento ins = new Instrumento();
		ins.setIdItem(codinst);
		Collection<Instrumento> lista = new ArrayList<Instrumento>();
		lista.add(ins);
		sala.setInstrumento(lista);

			new SalaDAO().armado(sala);
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
